package com.cn.yang.servlet;

import com.alibaba.fastjson.JSONObject;
import com.cn.yang.model.production.ProductModel;
import com.cn.yang.service.ProductService;
import com.cn.yang.service.impl.ProductServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/product/findById")
public class ProductFindByIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer id = req.getParameter("id")==null?0:Integer.valueOf(req.getParameter("id"));
        ProductService service = new ProductServiceImpl();
        ProductModel model = service.selectById(id);
    
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("productModel",model);
        resp.getWriter().println(jsonObject);
    }
}
